import 'package:flutter/material.dart';
import 'package:flutter_color_plugin/flutter_color_plugin.dart';

class AnimationTipPop extends StatefulWidget {
  // 传参：
  final String title;
  final String info;
  final String cancelText;
  final String confirmText;
  final Function cancelFunc;
  final Function confirmFunc;
  final bool  onlyConfirm;
  const AnimationTipPop(
      {Key key,
      this.title = '温馨提示',
      this.info,
      this.cancelText = '取消',
      this.confirmText = '确认',
      this.cancelFunc,
      this.confirmFunc,  this.onlyConfirm= false})
      : super(key: key);

  @override
  _AnimationTipPopState createState() => _AnimationTipPopState();
}

class _AnimationTipPopState extends State<AnimationTipPop>
    with SingleTickerProviderStateMixin {
  //  动画控制器
  AnimationController _controller;
  Animation<double> _animation;

  @override
  void initState() {
    super.initState();
    _controller =
        AnimationController(vsync: this, duration: Duration(milliseconds: 400));
    _animation = Tween(begin: 0.0, end: 1.0).animate(_controller);

    _animation.addStatusListener((status) {
      if (status == AnimationStatus.completed) {}
    });
    // 动画的播放
    _controller.forward();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    
    // return FadeTransition(
    //   opacity: _animation,
    //   child: TipPop(
    //     title: widget.title,
    //     info: widget.info,
    //     cancelText: widget.cancelText,
    //     cancelFunc: widget.cancelFunc,
    //     confirmText: widget.confirmText,
    //     confirmFunc: widget.confirmFunc,
    //     onlyConfirm: widget.onlyConfirm
    //   ),
    // );

    return ScaleTransition(
      scale: _animation,
      child: TipPop(
        title: widget.title,
        info: widget.info,
        cancelText: widget.cancelText,
        cancelFunc: widget.cancelFunc,
        confirmText: widget.confirmText,
        confirmFunc: widget.confirmFunc,
        onlyConfirm: widget.onlyConfirm
      ),
    );
  }
}

class TipPop extends StatelessWidget {
  // 传参：
  final String title;
  final String info;
  final String cancelText;
  final String confirmText;
  final Function cancelFunc;
  final Function confirmFunc;
  final bool onlyConfirm;

  const TipPop(
      {Key key,
      this.title = '温馨提示',
      this.info,
      this.cancelText = '取消',
      this.confirmText = '确定',
      this.cancelFunc,
      this.confirmFunc, this.onlyConfirm = false, })
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      // decoration: BoxDecoration(color: Color.fromRGBO(0, 0, 0, 0.8)),
      child: Center(
        child: Container(
          width: 280,
          height: 165,
          decoration: BoxDecoration(
              color: Colors.white, borderRadius: BorderRadius.circular(8)),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Container(
                height: 95,
                padding: EdgeInsets.only(left: 24, right: 24, top: 20),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    // 标题
                    Text(
                      title,
                      style: TextStyle(
                          color: ColorUtil.color("#FF333333"),
                          fontSize: 18,
                          decoration: TextDecoration.none,
                          fontWeight: FontWeight.bold),
                    ),
                    // 提示内容
                    LimitedBox(
                      maxWidth: 100,
                      child: Text(info,
                          maxLines: 5,
                          textAlign: TextAlign.center,
                          style: TextStyle(
                            color: ColorUtil.color("#FF333333"),
                            decoration: TextDecoration.none,
                            fontSize: 15,
                          )),
                    )
                  ],
                ),
              ),
              // 按钮
              Container(
                height: 49,
                decoration: BoxDecoration(
                    border: Border(
                        top: BorderSide(color: ColorUtil.color("#FFE5E5E5")))),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    !onlyConfirm ? Expanded(
                        flex: 1,
                        child: GestureDetector(
                          child: Container(
                            height: 49,
                            decoration: BoxDecoration(
                                border: Border(
                                    right: BorderSide(
                                        color: ColorUtil.color("#FFE5E5E5")))),
                            child: Center(
                              child: Text(
                                cancelText,
                                style: TextStyle(
                                    color: ColorUtil.color("#FF999999"),
                                    decoration: TextDecoration.none,
                                    fontSize: 18),
                                textAlign: TextAlign.center,
                              ),
                            ),
                          ),
                          onTap: () {
                            Navigator.pop(context);
                            cancelFunc;
                          },
                        )) : Text(""),
                    Expanded(
                        flex: 1,
                        child: GestureDetector(
                          child: Container(
                            height: 49,
                            child: Center(
                              child: Text(
                                confirmText,
                                style: TextStyle(
                                    color: ColorUtil.color("#FFC49226"),
                                    decoration: TextDecoration.none,
                                    fontSize: 18),
                                textAlign: TextAlign.center,
                              ),
                            ),
                          ),
                          onTap: () {
                            Navigator.pop(context);
                            confirmFunc;
                          },
                        )),
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
